﻿@{
    ViewBag.Title = "GetBillGood";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js?ver=1")" type="text/javascript"></script>         
}
<form id="form1" method="post">
<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">                
    <table style="width:100%;">
        <tr>
            <td width="80px" align="right">主供应商：</td>
            <td width="200px" >
                @Html.Partial("~/Views/Modular/LookUpSupply.cshtml")
            </td>
            <td style="white-space:nowrap;">
                @Html.Partial("~/Views/Modular/SearchInfoEx.cshtml")
            </td>
            <td style="width:100%;">
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-ok" onclick="onSelectGoods" plain="true">选择</a>
                <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>                
</div>
<div id="layout1" class="mini-layout" style="width:900px;height:430px;"  borderStyle="border:solid 1px #aaa;">

    <div title="商品分类" showProxyText="true" region="west" width="200" expanded="true" showSplitIcon="true">
        <div class="mini-fit">
            <ul id="tree1" class="mini-tree" url="" 
                style="width:100%;height:390px;" expandOnLoad="0"
                textField="FName" idField="FItemID" parentField="FParentID"  showTreeIcon="true" resultAsTree="false">        
            </ul>
        </div>
    </div>

    <div title="center" region="center">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="10" idField="FItemID" 
            allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true"
            borderStyle="border:0;" url="../Bill/GetBillGoodss"  multiSelect="true"
            allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
            onrowdblclick="onSelectOne" sortMode="client" >
                <div property="columns">
                <div type="checkcolumn"></div>
                <div type="indexcolumn" width="35" headerAlign="center" >序号</div>
                <div field="FCode" width="100" allowSort="true" headerAlign="center" >条码</div>
                <div field="FName" width="180" allowSort="true" headerAlign="center" >名称</div>
                <div field="FSpec" width="90" allowSort="true" headerAlign="center" >规格</div>
                <div field="FUnitName" width="50" allowSort="true" headerAlign="center" >单位</div>
                <div field="FPrice" name="FPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right">单价</div>
                <div field="FCorpName" width="80" allowSort="true" headerAlign="center" >所属商户</div>
                <div field="FNumber" width="90" allowSort="true" headerAlign="center" >编码</div>
           </div>
        </div>  
    </div>

    <div title="已选商品" showProxyText="true" region="east" showHeader="false" width="200"  showSplitIcon="true">
            <table>
                <tr>
                    <td><input type="button" value=">" onclick="adds()" style="width:40px;"/></td>
                    <td><input type="button" value=">>" onclick="addAll()" style="width:40px;"/></td>               
                    <td><input type="button" value="&lt;&lt;" onclick="removeAll()" style="width:40px;"/></td>
                    <td><input type="button" value="&lt;" onclick="removes()" style="width:40px;"/></td>
                </tr>
            </table>
            <div id="datagrid2" class="mini-datagrid" style="width:100%;height:388px;" idField="FItemID" multiSelect="true"
                borderStyle="border:0;" url="" allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                onrowdblclick="onOk" sortMode="client" showPager="false">
                <div property="columns">            
                <div type="checkcolumn" ></div>      
                <div type="indexcolumn" width="35" visible = "false" headerAlign="center" >序号</div>
                <div field="FCode" width="110"allowSort="true" headerAlign="center" >条码</div>  
                <div field="FName" width="130"allowSort="true" headerAlign="center" >名称</div>   
                <div field="FSpec" width="80"allowSort="true" headerAlign="center" >规格</div>   
                <div field="FUnitName" width="45"allowSort="true" headerAlign="center">单位</div>   
                <div field="FNumber" width="80"allowSort="true" visible = "false" headerAlign="center" >编码</div>  
                </div>
            </div>         
    </div>

</div>
        <script type="text/javascript">
            mini.parse();
            var mBillType = "0";
            var mStockID = 0;
            var FObjectID = 0;
            var uID = parent.window.getSystemAppID();
            var grid1 = mini.get("datagrid1");
            var grid2 = mini.get("datagrid2");
            

            //通用shown自动调用些方式
            function FormShown() {
                if(mBillType==1 || mBillType==-1 || mBillType==10 || mBillType==11 || mBillType==12 || mBillType==20)
                    InitGrid("GetBillGoods");
                var tree = mini.get("tree1");
                tree.on("nodeselect", function (e) {
                    LoadListData();
                });
            }

            //加载分类树
            function LoadListTree() {
                var tree = mini.get("tree1");
                var mAppID = parent.window.getSystemAppID();
                var json = '[{"mSystemAppID":"' + mAppID + '"}]'
                $.post('../Goods/GetGoodsClass', { mjson: mAppID }, function (data) {
                    tree.loadList(mini.decode(data));
                    tree.select(0);
                });
            }

            function setkeyPress() {
                if (event.keyCode == 13) {
                    LoadListData();
                }
            }

            //加载资料
            function SetData(data) {
                if (data.key != null) {
                    var txtValue = data.key;
                    var sNumber = "";
                    var sName = "";
                    var pattern = new RegExp("[\u4E00-\u9FA5]+");
                    var pattern3 = new RegExp("[0-9]+");
                    if (pattern.test(txtValue)) {
                        //alert('该字符串是中文');
                        mini.getbyName("FName").setValue(txtValue);
                    }
                    else
                        if (pattern3.test(txtValue)) {
                            //sNumber = txtValue;
                            mini.getbyName("FSearchKey").setValue(txtValue);
                            //alert('该字符串是数字');
                        } else {
                            //sName = txtValue;
                            mini.getbyName("FName").setValue(txtValue);
                        }

                    //mini.getbyName("FSearchKey").setValue(data.key);
                }
                if (data.mBillType != null) {
                    mBillType = data.mBillType;
                }
                if (data.mStockID != null) {
                    mStockID = data.mStockID;
                }
                if (data.FObjectID != null) {
                    FObjectID = data.FObjectID;
                }
                LoadListTree();
            }

            //加载资料
            function search() {
                LoadListData();
            }
            
            //加载用户列表
            function LoadListData() {
                var mSupplierID = mini.getbyName("FSupplyItemID").getValue();
                var mSuppName = mini.getbyName("FSupplyName").getValue();
                if (mSuppName == "") mSupplierID = "-1";
                var tree = mini.get("tree1");
                var mload = tree.getData();
                if (mload.length > 0) {
                    var node = tree.getSelectedNode();
                    var classid = node.FItemID;
                    var json = "[{";
                    json = json + "'FClassID':" + "'" + classid + "',";
                    json = json + "'FBillType':" + "'" + mBillType + "',";
                    json = json + "'FSupplierID':" + "'" + mSupplierID + "',";
                    json = json + "'FNumber':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
                    json = json + "'FName':'" + mini.getbyName("FName").getValue() + "',";
                    json = json + "'FStockID':'" + mStockID + "',";
                    json = json + "'FObjectID':'" + FObjectID + "',";
                    json = json + "'FSystemAppID':'" + parent.window.getSystemAppID() + "'}]";
                    var grid = mini.get("datagrid1");
                    grid.load({ datajson: json });
                }
            }

            function onSelectGoods(e) {
                var grid2 = mini.get("datagrid2");
                var grid1 = mini.get("datagrid1");
                var rCnt = grid2.getData().length;
                if (rCnt > 0) {
                    var rec = grid2.getData();
                }
                else {
                    var rec = grid1.getSelecteds();
                }
                if (rec) {
                    CloseWindow(rec);
                }
            }

            function adds() {
                var items = grid1.getSelecteds();
                grid1.removeRows(items);
                grid2.addRows(items);
            }
            function addAll() {
                var items = grid1.getData();
                grid1.removeRows(items);
                grid2.addRows(items);
            }
            function removes() {
                var items = grid2.getSelecteds();
                grid2.removeRows(items);
                grid1.addRows(items);
            }
            function removeAll() {
                var items = grid2.getData();
                grid2.removeRows(items);
                grid1.addRows(items);
            }

    </script>

</form>